package org.example.listener;

import lombok.extern.slf4j.Slf4j;
import org.example.GreetingsStreams;
import org.example.pojo.Greetings;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Splitter;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;

//@Component
@Slf4j
public class GreetingsListener {
//    @StreamListener(GreetingsStreams.INPUT)
//    @SendTo(GreetingsStreams.OUTPUT_OTHER)
    @ServiceActivator(inputChannel = GreetingsStreams.INPUT , outputChannel = GreetingsStreams.OUTPUT_OTHER)
    public Greetings handleGreetingsAndSendTo(@Payload Greetings greetings, @Headers MessageHeaders headers) {
        log.info("handleGreetingsAndSendTo received greetings: {} ,headers:{}", greetings,headers.keySet());
        return greetings;
    }
    @StreamListener(GreetingsStreams.INPUT)
    public void handleGreetings1(@Payload Greetings greetings, @Headers MessageHeaders headers) {
        log.info("handleGreetings1 received greetings: {} ,headers:{}", greetings,headers.keySet());

    }
    @StreamListener(target = GreetingsStreams.INPUT, condition = "headers['test']=='test'")
    public void handleGreetings2(@Payload Greetings greetings, @Headers MessageHeaders headers) {
        log.info("handleGreetings2 received greetings: {} ,headers:{}", greetings,headers.keySet());
    }

}
